CC = gcc
INCLUDE = -I. -I/usr/local/dao/include -Iwrap
LIB = -L. -L/usr/lib
CFLAG = -c -fPIC
LFLAG =

OBJS = wrap/dao_SDL.o wrap/dao_SDL2.o wrap/dao_SDL3.o

BIND_CONFIG = dir_output=wrap dir_inc=SDL fixing=fixing.txt onload=DaoOnLoad2

TARGET = DaoSDL.so

UNAME = $(shell uname)

ifeq ($(UNAME), Linux)
  INCLUDE += -I/usr/local/include/
  CFLAG += -DUNIX
  LFLAG += -fPIC -shared -Wl,-soname,libDaoSDL.so -lSDL
  OBJS += daoInitLinuxSDL.o
  BIND_CONFIG += dir_input=/usr/include/SDL
endif

ifeq ($(UNAME), Darwin)
  TARGET = DaoSDL.dylib
  INCLUDE += -I/Library/Frameworks/SDL.framework/Headers
  CFLAG += -DUNIX -DMAC_OSX
  LFLAG += -fPIC -dynamiclib -undefined dynamic_lookup -install_name libDaoSDL.dylib
  LFLAG += -framework SDL -framework Cocoa -framework OpenGL 
  OBJS += daoInitMacSDL.o
  BIND_CONFIG += dir_input=/Library/Frameworks/SDL.framework/Headers
endif

first: all

all: $(TARGET)

.SUFFIXES: .c .m

.c.o:
	$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<

.m.o:
	$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<

daoSQL.o: daoSQL.c daoSQL.h
	$(CC) $(CFLAG) $(INCLUDE) daoSQL.c

$(TARGET): $(OBJS)
	$(CC) $(LFLAG) $(LIB) $(OBJS) -o $(TARGET)

clean:
	rm *.o



HD_SDL = SDL_stdinc.h,SDL_types.h,SDL.h,SDL_active.h,SDL_cdrom.h,SDL_cpuinfo.h,SDL_audio.h,SDL_getenv.h,SDL_joystick.h,SDL_loadso.h,SDL_mutex.h,SDL_thread.h,SDL_timer.h,SDL_error.h,SDL_video.h,SDL_keysym.h,SDL_keyboard.h,SDL_mouse.h,SDL_events.h,SDL_rwops.h

HD_GFX = SDL_gfxPrimitives.h,SDL_imageFilter.h,SDL_rotozoom.h

bind:
	@test -d wrap || mkdir wrap
	autobind.dao $(HD_SDL) wrap_name=SDL $(BIND_CONFIG)
	autobind.dao SDL_image.h $(BIND_CONFIG)
	autobind.dao SDL_net.h $(BIND_CONFIG)
	autobind.dao SDL_ttf.h $(BIND_CONFIG)
	autobind.dao $(HD_GFX) wrap_name=SDL_gfx $(BIND_CONFIG)
